<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button>get-输出</button>
<button>get-弹出</button>
</body>
<script>
    const btns = document.querySelectorAll("button");

    function ajax(url) {
        return new Promise((resolve,reject)=>{
            const xhr = new XMLHttpRequest();
            xhr.open("get", url);
            xhr.send();
            xhr.onload = function () {
                resolve(xhr.response);
            }
            xhr.onerror = function(){
                reject("异常"+xhr.status+xhr.statusText);
            }
        })

    }

    btns[0].onclick = function () {
        ajax("../12-async-await/1-async函数.html").then(value=>{
            console.log(value);
        });
    }
    btns[1].onclick = function () {
        ajax("http://127.0.0.1:9080").then(value=>{
            alert(value);
        }).catch(reason=>{
            alert(reason)
        })
    }
</script>
</html>